import os
import time
from paddleocr import PaddleOCR

# 初始化PaddleOCR
ocr = PaddleOCR(use_angle_cls=True, lang="ch", use_gpu=True)

# 图片文件夹路径
img_folder = 'D:/Project/All_Project/Python/blct/imges/csimages/'
img_paths = [os.path.join(img_folder, img) for img in os.listdir(img_folder) if img.endswith('.png')]

# 遍历文件夹中的所有图片
for img_path in img_paths:
    
    time.sleep(10)
    print(f"正在处理图片: {img_path}")
    # 记录推理开始时间
    start_time = time.time()
    # 进行OCR推理
    result = ocr.ocr(img_path, cls=True)
    # 记录推理结束时间
    end_time = time.time()

    # 计算推理时间
    inference_time = end_time - start_time
    print(f"推理时间: {inference_time:.4f} 秒")

    # 输出OCR结果
    for idx in range(len(result)):
        res = result[idx]
        for line in res:
            print(line)

    print("\n" + "="*30 + "\n")
